package sort;

import java.util.Arrays;

/**
 * 快速排序
 */
public class QuickSort {
    public static void main(String[] args) {
        int[] ints = {9, 2, 1, 8, 7, 5, 3, 4, 6};
        quick(ints,0,ints.length-1);
        System.out.println(Arrays.toString(ints));
    }
    public static void quick(int [] arr,int begin,int end){
        int low = begin;
        int high = end;
        if (low>=high){
            return;
        }

        int pivot  = arr[low]; //9

        while (low < high){
            while (low < high && arr[high] >= pivot){
                high--;
            }

            arr[low] = arr[high];

            while (low < high && arr[low] <= pivot){
                low++;
            }
            arr[high] = arr[low];

        }
        //todo 这个意义在哪
        arr[low] = pivot;
        quick(arr,begin,low-1);
        quick(arr,low+1,end);
    }
}
